package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.EmployeeAddNewDTO;
import cn.tedu.eb_film.pojo.dto.EmployeeUpdateDTO;
import cn.tedu.eb_film.pojo.dto.OrderAddNewDTO;
import cn.tedu.eb_film.pojo.dto.OrderUpdateDTO;
import cn.tedu.eb_film.pojo.vo.EmployeeListItemVO;
import cn.tedu.eb_film.pojo.vo.EmployeeStandardVO;
import cn.tedu.eb_film.pojo.vo.OrderListItemVO;
import cn.tedu.eb_film.pojo.vo.OrderStandardVO;
import cn.tedu.eb_film.service.EmployeeService;
import cn.tedu.eb_film.service.OrderService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理订单相关请求的控制器类
 *
 * @author zzzzc
 * @version 0.0.1
 */

@Api(tags = "订单管理模块")
@Slf4j
@RestController
@RequestMapping("/orders")
@Validated
public class OrderController {

    @Autowired
    private OrderService orderService;
    public OrderController(){
        log.debug("创建控制器类对象：EmployeeController");
    }

    // http://localhost:8888/employees/add-new
    @PostMapping("/add-new")
    @ApiOperation("添加订单")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid OrderAddNewDTO orderAddNewDTO){
        log.debug("开始处理【添加订单】的请求，参数：{}",orderAddNewDTO);
        orderService.addNew(orderAddNewDTO);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改订单")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "订单ID", required = true, dataType = "long")
    public JsonResult<Void> updateInfoById(@PathVariable@Range(min = 1,message = "请提交有效的id")Long id,
                                           @Valid OrderUpdateDTO orderUpdateDTO){
        log.debug("开始处理【修改订单详情】的请求，ID：{}，新数据：{}", id, orderUpdateDTO);
        orderService.updateInfoById(id,orderUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}/select")
    @ApiOperation("根据id查询订单")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "订单ID", required = true, dataType = "long")
    public JsonResult<OrderStandardVO> getStandardById(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id){
        log.debug("开始处理【根据ID查询订单详情】的请求，参数：{}", id);
        OrderStandardVO standardById = orderService.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    @GetMapping("")
    @ApiOperation("查询订单列表")
    @ApiOperationSupport(order = 410)
    public JsonResult<List<OrderListItemVO>> list(){
        log.debug("开始处理【查询订单列表】的请求，无参数");
        List<OrderListItemVO> list = orderService.list();
        return JsonResult.ok(list);
    }
}
